package com.ai.exam.service.impl;

import com.ai.exam.dao.ClickRecordMapper;
import com.ai.exam.dao.RecordDicMapper;
import com.ai.exam.dto.WxModel;
import com.ai.exam.model.ClickRecord;
import com.ai.exam.model.RecordDic;
import com.ai.exam.service.ClickRecordService;
import com.ai.exam.core.AbstractService;
import com.ai.exam.util.BaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * Created by CodeGenerator on 2018/06/01.
 */
@Service
@Transactional
public class ClickRecordServiceImpl extends AbstractService<ClickRecord> implements ClickRecordService {
    private Logger logger = LoggerFactory.getLogger(ClickRecordServiceImpl.class);
    @Resource
    private ClickRecordMapper clickRecordMapper;
    @Resource
    private RecordDicMapper recordDicMapper;

    @Override
    public void onClick(WxModel wxModel) {
        logger.info("记录点击，参数{}",wxModel);
        RecordDic qs = new RecordDic();
        qs.setdKey(wxModel.getClickTyep());
        logger.info("按类型查询字典表，参数{}",qs);
        RecordDic rs = recordDicMapper.selectOne(qs);
        logger.info("查询字典结果{}",rs);
        if(rs!=null){
            ClickRecord cr = new ClickRecord();
            cr.setId(BaseUtil.getUUID());
            cr.setOpenId(wxModel.getOpenId());
            cr.setRecordId(rs.getId());
            cr.setTelnum(wxModel.getTelNum());
            logger.info("插入点击记录{}",cr);
            int i = clickRecordMapper.insertSelective(cr);
            logger.info("插入条数{}",i);
        }else{
            logger.info("未找到指定类型，无法插入记录");
        }
    }
}
